module.exports = app => {
  const mongoose = app.mongoose
  const { Schema } = mongoose
  const { ObjectId } = Schema

  const modelSchema = new Schema({
    name: { type: String, remark: '服务器名称', required: true },
    host: { type: String, remark: '服务器 IP', required: true },
    token: { type: String, remark: '服务器 token', required: true },
    module: [
      { type: String, remark: '服务器运行模块' },
    ],
    upType: { type: Number, required: true, default: 0, remark: '方式' },
    rate: { type: Number, remark: '上报速率' },
    user: { type: ObjectId, ref: 'user', remark: '服务器所属用户' },
    remark: { type: String, remark: '备注说明' },
  }, {
    collections: 'server',
    timestamps: true,
  })

  modelSchema.index({ host: 1 })
  modelSchema.index({ token: 1 })

  return mongoose.model('server', modelSchema)
}